This notebook can be used to generate basic scatter plots of all the Pareto-optimal fronts with suitable colorings and point-sizes. All the Pareto-optimal data point files hard-coded in the dictionary pfs. Currently this notebook provides these Pareto-optimal fronts.
%matplotlib notebook
%reload_ext autoreload
%autoreload 2
import sys
import os
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.cm as cm
import matplotlib.colors as mc
from mpl_toolkits.mplot3d import Axes3D
plt.rcParams.update({'figure.max_open_warning': 0})
sys.path.append('../')
from vis.utils import io
from vis.utils import transform as tr
def load_props(path):
r"""
Load CV, Mu, Ik and S from path.
"""
CV = None
cvpathf = os.path.join(path, "datacv.csv")
if os.path.exists(cvpathf):
CV = np.loadtxt(cvpathf)
# load the Mu values
Mu = None
mupathf = os.path.join(path, "mu.csv")
if os.path.exists(mupathf):
Mu = np.loadtxt(mupathf)
# load the knee indices
Ik = None
kpathf = os.path.join(path, "muid.csv")
if os.path.exists(kpathf):
Ik = np.loadtxt(kpathf, dtype = int)
return CV, Mu, Ik
def decide_size_color(CV, Mu, Ik):
r"""
Decide point-size and color from `CV`, `Mu` and `Ik`
"""
# decide point-size
S = 1
if Mu is not None and Ik is not None:
S = tr.resize_by_tradeoff(Mu, k = Ik)
# decide colors
# C = tr.default_color(F.shape[0], alpha = 0.5)
M = np.mean(F, axis = 0)
C = tr.color_by_dist(F, M)
# if CV is available, use CV to color
if CV is not None:
C = tr.color_by_cv(CV)
# enhance knee points
if Ik is not None:
C = tr.enhance_color(C, Ik)
return S, C
pfs = {'dtlz2': ['3d', '4d', '8d'], \
'dtlz2-nbi': ['3d', '4d', '8d'], \
'debmdk': ['3d', '4d', '8d'], \
'debmdk-nbi': ['3d', '4d', '8d'], \
'debmdk-all': ['3d', '4d', '8d'], \
'debmdk-all-nbi': ['3d', '4d', '8d'], \
'dtlz8': ['3d', '4d', '6d', '8d'], \
'dtlz8-nbi': ['3d', '4d', '6d', '8d'], \
'c2dtlz2': ['3d', '4d', '5d', '8d'], \
'c2dtlz2-nbi': ['3d', '4d', '5d', '8d'], \
'cdebmdk': ['3d', '4d', '8d'], \
'cdebmdk-nbi': ['3d', '4d', '8d'], \
'c0dtlz2': ['3d', '4d', '8d'], \
'c0dtlz2-nbi': ['3d', '4d', '8d'], \
'crash-nbi': ['3d'], 'crash-c1-nbi': ['3d'], 'crash-c2-nbi': ['3d'], \
'gaa': ['10d'], \
'gaa-nbi': ['10d']}
for pf in list(pfs.keys()):
for dim in pfs[pf]:
fullpathf = "../data/{0:s}/{1:s}/dataf.csv".format(pf, dim)
if os.path.exists(fullpathf):
path, filenamef = os.path.split(fullpathf)
dirs = path.split('/')
frontname = dirs[-2]
# load the front
F = np.loadtxt(fullpathf, delimiter = ',')
print(fullpathf, F.shape, dirs, frontname)
CV, Mu, Ik = load_props(path)
S,C = decide_size_color(CV, Mu, Ik)
figpath = os.path.join(path, "scatter3d.pdf")
with plt.rc_context({"text.usetex": True, "font.size": 12}):
fig = plt.figure()
ax = Axes3D(fig)
ax.xaxis.set_rotate_label(False)
ax.yaxis.set_rotate_label(False)
ax.zaxis.set_rotate_label(False)
ax.set_xlabel(r"$f_1$")
ax.set_ylabel(r"$f_2$")
ax.set_zlabel(r"$f_3$")
ax.scatter(F[:,0], F[:,1], F[:,2], c = C, s = S)
# save the fig
plt.savefig(figpath, bbox_inches = 'tight', pad_inches = 0, dpi = 150)
plt.show()